# coding: utf-8

import os, uuid
from model.utils import current_timestamp
from handler.image import *
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

base_dir = os.getcwd()
model_dir = os.path.join(base_dir, 'model')
source_dir = os.path.join(base_dir, 'source')

def download_image():
    image_url = 'http://service.cpic.com.cn/common/generateCaptcha?{0}'.format(current_timestamp())
    image = download_to_image(image_url)
    image_file = '{0}.jpg'.format(uuid.uuid4())
    image_path = os.path.join(source_dir, image_file)
    image.save(image_path)
    print('download {0} success!'.format(image_file))


def main():
    for i in xrange(200):
        download_image()
    print('done!')

if __name__ == '__main__':
    main()